'''
根据请求, 存储接口调用日志
'''
from apps.logs.models import ApiLogs
import json

def save_log(request, param: dict, result: dict, model=ApiLogs):
    '''
    :param model: ApiLogs, 记录存储
    :param request: 请求接口, 统一 request
    :param param: 入参, 即通过 post 提交的参数
    :param result: 出参, 响应结果
    :return: bool, True or False
    '''
    api_name = request.META.get("PATH_INFO")
    param = json.dumps(param)
    result = json.dumps(result)

    try:
        model.objects.create(
            name=api_name,
            params=param,
            result=result
        )
    except:
        print(api_name, param, result)
    return True
